﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

using Telerik.Windows.Controls;
using NHibernate;
using BrokerBase.Lib.DataBase;
using System.Data.SqlClient;

namespace Broker.Mgr
{
    /// <summary>
    /// Interaction logic for ConfigPage.xaml
    /// </summary>
    public partial class ConfigPage
    {
        public ConfigPage()
        {
            InitializeComponent();
        }


        private void UpdateCheckPoint()
        {
            ISession sess = AppGlobal.HbmSessionFactory.GetCurrentSession();

            IList<DBTable> tables = sess.CreateQuery("from DBTable").List<DBTable>();

            SqlConnection conn = (SqlConnection)sess.Connection;

            ITransaction tx = sess.BeginTransaction();

            try
            {

                foreach (DBTable t in tables)
                {
                    //Debug.Assert(t.Name != "Product_FixRateRecord");

                    t.LastTimeStamp = t.LoadLastTimeStamp(sess);

                    sess.Save(t);
                }

                tx.Commit();
                MessageBox.Show("更新成功!");
            }
            catch (Exception er)
            {
                tx.Rollback();
                throw new Exception("更新下载检查点时发生错误!" + er.Message);
            }
        }

        private void btnCheckPoint_Click(object sender, RoutedEventArgs e)
        {
            UpdateCheckPoint();
        }
    }
}
